package com.buobao.spring.jdbc;

import com.buobao.spring.jdbc.dao.EmployeeDao;
import com.buobao.spring.jdbc.entity.Employee;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class SpringApplication {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        EmployeeDao employeeDao = (EmployeeDao) context.getBean("employeeDao");
        Employee byId = employeeDao.findById(7369);
        System.out.println(byId.getEname());

        System.out.println();
        List<Map<String, Object>> sales = employeeDao.findMapByDname("SALES");
        sales.stream().forEach(m->{
            System.out.println(m.get("ename"));
        });

        System.out.println();
        List<Employee> list = employeeDao.findByDeptno(10);
        list.stream().forEach(e->{System.out.println(e.getEmpno());});

        Employee employee = new Employee();
        employee.setEmpno(8888l);
        employee.setEname("new insert");
        employee.setHiredate(new Date());
        employee.setMgr(7698l);
        employee.setSal(8000.0);
        employee.setComm(10.0);
        employee.setJob("test job");
        employee.setEname("张泽涛");
        employee.setDeptno(10l);
        employeeDao.update(employee);
    }
}
